package chapter17;

import java.io.*;
import java.util.Scanner;

public class her_Secret {
    public static void main(String[] args) throws IOException {
        // Check if source file exists
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入要复制的文件地址：");
        String path = scan.next();
        File sourceFile = new File(path);
        if (!sourceFile.exists()) {
            System.out.println("Source file " + path
                    + " does not exist");
            System.exit(2);
        }
        System.out.println("原文件为：");
        try (
                // Create an input stream for the file
                FileInputStream Secret = new FileInputStream(path);
        ) {
            // Read values from the file
            int value;
            while ((value = Secret.read()) != -1) {
                System.out.print(value + " ");
            }
        }

        // Check if target file exists
        File targetFile = new File("Her.txt");
        if (targetFile.exists()) {
            System.out.println("Target file " + "Her.txt"
                    + " already exists");
            System.exit(3);
        }
        try (
                // Create an input stream
                BufferedInputStream input =
                        new BufferedInputStream(new FileInputStream(sourceFile));

                // Create an output stream
                BufferedOutputStream output =
                        new BufferedOutputStream(new FileOutputStream(targetFile));
        ) {
            // Continuously read a byte from input and write it to output
            int r= 0;
            while ((r = input.read()) != -1) {
                r= r+5;
                output.write((byte)r);
            }
        }
        System.out.println();
        System.out.println("加密完成");
    }
}